/*
 * ESHardGrey.cs
 *
 * Created on January 4, 2008, 6:38 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * Copyright (C) 2010       Mathijs Miermans
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */


using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace HexTD
{
	public class ESHardGrey : EnemySpriteBase
	{

		private int prevPaintTime;
		private Color bodyColor = new Color(255, 150, 150, 150);
#if PORT
		private Brush bodyStroke;
		private Shape bodyShape;
#endif
		private static float reductionFactor = 0.005f;
		private static string infoText =
				"<h1>Hard Grey Box</h1>" +
				"<p>" +
				"It's a box, it's grey, it's boring.<br>" +
				"But it's harder to kill then normal." +
				"</p>";

		/** Creates a new instance of ESHardGrey */
		public ESHardGrey(Game game)
			: base(game, "Hard Grey")
		{
			this.damageColor = COLOR.OTHER;
			this.damageColorAnti = COLOR.OTHER;
		}

		public override string getInfostring()
		{
			return infoText =
					"<h1>Hard Grey Box</h1>" +
					"<p>" +
					"It's a box, it's grey, it's boring.<br>" +
					"But it's harder to kill then normal.</p>" +
					"<p><b>Damage Reduction:</b> " + Math.Round(reductionFactor * this.healthMax).ToString(form) + "<br>" +
					"" + base.getInfostring() + "</p>";
		}

		protected override void doDamage(int damage)
		{
			long realDamage = (long)Math.Round(damage - reductionFactor * this.healthMax);
			realDamage = Math.Max(realDamage, 1);

			if (this.validTarget())
			{
				this.health -= realDamage;
			}
			if (this.health <= 0)
			{
				this.isValidTarget = false;
				this.dead = true;
				this.context.addScore(this.price);
				this.context.doReceive(this.price);
				this.context.removeEnemy();
			}
			this.fireStatusChangedEvent();
		}

		public override void resetScale()
		{
#if PORT
			base.resetScale();
			Cache cache = this.context.getCache();

			if (cache.hasShape("ESHGShape" + this.size.letter)) {
				this.bodyShape = cache.getShape("ESHGShape" + this.size.letter);
			} else {

				float scale = this.context.paintScale * this.size.scaleMod;
				float r = scale / 6;

				float[,] points = {
					{+r, +r},
					{+r, -r},
					{-r, -r},
					{-r, +r}
				};
				this.bodyShape = Geometry.coordsToGeneralPath(points, true);
				cache.putShape("ESHGShape" + this.size.letter, this.bodyShape);
			}
			this.bodyStroke = new Brush(3.5f * this.context.strokeScale, Brush.CAP_ROUND, Brush.JOIN_ROUND);
#endif
		}

		public override void Draw(GameTime gameTime)
		{
#if PORT
			if (this.inactive || this.dead) {
				this.prevPaintTime = gameTime;
			} else {
				Brush defaultStroke = g2.getStroke();
				this.prevPaintTime = gameTime;

				RotateTransform saveXform = g2.getTransform();
				g2.transform(atTranslate);

				if (this.shielded) {
					this.paintShield_bottom(g2);
				}
				this.paintHealthLine(g2);

				g2.setColor(this.bodyColor);
				g2.setStroke(this.bodyStroke);
				g2.draw(this.bodyShape);
				g2.setTransform(saveXform);

				if (this.shielded) {
					g2.transform(atTranslate);
					this.paintShield_top(g2);
					g2.setTransform(saveXform);
				}
			
				base.paintSelected(g2);

				g2.setStroke(defaultStroke);
			}
#endif
		}
	}
}